<?php

namespace app\admin\controller;

use app\admin\service\LoginService;
use app\admin\service\MenuService;
use app\common\Annotation\ControllerAnnotation;
use app\common\controller\BackendController;
use app\common\model\MenuModel;
use app\common\service\SystemService;

/**
 * Class IndexController
 * @ControllerAnnotation(title="首页",auth=1)
 * @package app\admin\controller
 */
class IndexController extends BackendController
{
    public function index()
    {
        return $this->fetch("layout/menu"); //单入口
    }

    public function menu()
    {
        $admin_id = LoginService::getAdminId();
        $node_arr = LoginService::getAdminNodeArr($admin_id); //一维数组node
        $menuList = MenuService::getMenuData();
        $menuInfo = MenuService::buildMenuChild(0, $menuList, $node_arr);
        $index_url_model = MenuModel::field("url")->where(["is_index" => 1])->find();
        $menu_arr = [
            "homeInfo" => [
                "title" => "首页",
                "href" => url(str_replace(".", "/", $index_url_model->url))
            ],
            "logoInfo" => [
                "title" => get_sysconfig("site_title"),
                "image" => get_sysconfig("site_logo"),
                "href" => url("index/index")
            ],
            "menuInfo" => $menuInfo,
        ];
        return $menu_arr;


        $menu_arr = MenuService::getAdminMenu();
        return json($menu_arr);
    }


    public function clear_cache()
    {
        SystemService::clearCache();
        return json(["code" => 1, "msg" => "服务端清理缓存成功"]);
    }


    public function welcome()
    {
        return $this->fetch();
    }
}
